package com.zzzyh.forumsystemclient.services.impl;

import com.zzzyh.forumsystemclient.dao.ArticleTagMapper;
import com.zzzyh.forumsystemclient.dao.TagMapper;
import com.zzzyh.forumsystemclient.model.Tag;
import com.zzzyh.forumsystemclient.services.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagServiceImpl implements ITagService {
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private ArticleTagMapper articleTagMapper;


    @Override
    public List<Tag> list() {
        List<Tag> tags = tagMapper.list();
        for (Tag tag : tags){
            tag.setArticleNum(articleTagMapper.countByTagId(tag.getId()));
        }
        return tags;
    }

    @Override
    public void add(Integer tagId, Long articleId) {
        tagMapper.addTag(tagId, articleId);
    }
}
